package cn.itsource.wechat.controller;

import cn.itsource.util.JsonResult;
import cn.itsource.wechat.bean.WeChatDto;
import cn.itsource.wechat.service.IWeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : 张金铭
 * @description :
 * @create :2022-11-18 10:26:00
 */
@Controller
@RequestMapping("/wechat")
@Slf4j
public class WeChatController {

    @Resource
    private IWeChatService weChatService;


    @GetMapping("/tologin")
    public void toLogin(HttpServletResponse resp) throws IOException {
//      return weChatService.tologin();
        resp.sendRedirect(weChatService.tologin());
    }

    @GetMapping("/callback")
    public void callback(String code,HttpServletResponse resp) throws IOException {

        resp.sendRedirect(weChatService.callback(code));
    }

    @PostMapping("/binder")
    @ResponseBody
    public JsonResult binder(@RequestBody WeChatDto user){
        return weChatService.binder(user);
    }


}
